﻿using Microsoft.AspNetCore.Mvc;
using orm.sqlsugar.api.Entities;
using SqlSugar;

namespace orm.sqlsugar.api.Controllers
{
    /// <summary>
    /// 批量操作
    /// </summary>
    public class BatchController(ISqlSugarClient sqlSugarClient) 
        : SqlSugarBaseController(sqlSugarClient)
    {
        /// <summary>
        /// 价格 + 1
        /// </summary>
        [HttpPut]
        public async Task<IActionResult> Update()
        {
            return Ok(await SqlSugarClient
                .Updateable<Order>()
                .SetColumns(o => o.TotalPrice == o.TotalPrice + 1)
                .Where(o => true)
                .ExecuteCommandAsync() > 0);
        }

        [HttpDelete]
        public async Task<IActionResult> Delete()
        {
            return Ok(await SqlSugarClient
                .Deleteable<Order>()
                .Where(o => o.IsDeleted == false)
                .ExecuteCommandAsync() > 0);
        }
    }
}
